package com.livegoods.listener;

import com.livegoods.LivegoodsBuyMessage;
import com.livegoods.LivegoodsMessage;
import com.livegoods.service.BuyactionService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BuyactionListener {


    @Autowired
    private BuyactionService buyactionService;

    @RabbitListener(bindings = {
           @QueueBinding(value=@Queue(name = "${livegoods.buyaction.queue}",autoDelete = "false"),
                   exchange = @Exchange("${livegoods.buyaction.exchange}")
                   ,key = "${livegoods.buyaction.routingKey}")
    })
    public Object receiveMessage(LivegoodsBuyMessage livegoodsBuyMessage){

        boolean result = buyactionService.buyaction(livegoodsBuyMessage.getId(), livegoodsBuyMessage.getUser());


        return result;
    }

}
